$.ajaxSetup({
    beforeSend: function(xhr) {
        xhr.setRequestHeader("token",localStorage.getItem("token"));
    },
    contentType:'application/x-www-form-urlencoded; charset=UTF-8',
    complete : function(XMLHttpRequest, textStatus) {
        var redirect = XMLHttpRequest.getResponseHeader("state");
        if (redirect == "error") {
            var win = window;
            while (win != win.top){
                win = win.top;
            }
            win.location.href= XMLHttpRequest.getResponseHeader("Path");
        }
    }
});

